/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConnectDialog.java
 *
 * Created on Nov 7, 2011, 9:04:52 PM
 */
package client;

import market.MarketItem;

/**
 *
 * @author Igor
 */
public class BuyWishDialog extends javax.swing.JDialog {
    MarketItem item;

    /** Creates new form ConnectDialog */
    public BuyWishDialog(java.awt.Frame parent, boolean modal, MarketItem item) {
        super(parent, modal);
        initComponents();
        this.item = item;
        // Load data from item.
        itemNameTxt.setText(item.getName());
        priceTxt.setText(Float.toString(item.getPrice()));
        ownerTxt.setText(item.getOwner());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        itemNameTxt = new javax.swing.JTextField();
        buyWishButon = new javax.swing.JButton();
        priceTxt = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        ownerTxt = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cancelBuyWishButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Match found");
        setResizable(false);

        jLabel1.setText("Item:");

        itemNameTxt.setEditable(false);
        itemNameTxt.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        buyWishButon.setText("Buy");

        priceTxt.setEditable(false);
        priceTxt.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel2.setText("Price:");

        ownerTxt.setEditable(false);
        ownerTxt.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel3.setText("Owner:");

        cancelBuyWishButton.setText("Cancel");
        cancelBuyWishButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBuyWishButtonActionPerformed(evt);
            }
        });

        buyWishButon.addActionListener(buyWishItemListener);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(ownerTxt)
                            .addComponent(priceTxt, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(itemNameTxt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(buyWishButon, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelBuyWishButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(itemNameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(priceTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(ownerTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelBuyWishButton)
                    .addComponent(buyWishButon))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-269)/2, (screenSize.height-199)/2, 269, 199);
    }// </editor-fold>//GEN-END:initComponents

    private void cancelBuyWishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBuyWishButtonActionPerformed
        dispose();
    }//GEN-LAST:event_cancelBuyWishButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buyWishButon;
    private javax.swing.JButton cancelBuyWishButton;
    private javax.swing.JTextField itemNameTxt;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField ownerTxt;
    private javax.swing.JTextField priceTxt;
    // End of variables declaration//GEN-END:variables
    //Letter listener
    java.awt.event.ActionListener buyWishItemListener = new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            dispose();//setVisible(false);
            ((ClientUI) getParent()).buyItem(item);
        }
    };
}
